<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.0.2">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.14.0/css/all.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"wanglong_kevin.gitee.io","root":"/","scheme":"Gemini","version":"8.0.0-rc.5","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false};
  </script>

  <meta name="description" content="背景介绍为了保持IPv4业务持续性和促进IPv6产业的发展性，4over6场景凭借其兼顾IPv4业务和IPv6发展的特点， 成为长期演进方案研究的焦点。在4over6场景中，MAP技术结合了无状态和双重翻译&#x2F;封装技术， 成为目前IETF关注度最高的解决方案。MAP（Mapping Address and Port）技术是指无状态地对地址 和端口进行复用，根据报文格式又分为双重封装MAP-E和双重翻">
<meta property="og:type" content="article">
<meta property="og:title" content="Map-T rule">
<meta property="og:url" content="https://wanglong_kevin.gitee.io/2018/12/31/MapT-rule/index.html">
<meta property="og:site_name" content="冬天里的小木屋">
<meta property="og:description" content="背景介绍为了保持IPv4业务持续性和促进IPv6产业的发展性，4over6场景凭借其兼顾IPv4业务和IPv6发展的特点， 成为长期演进方案研究的焦点。在4over6场景中，MAP技术结合了无状态和双重翻译&#x2F;封装技术， 成为目前IETF关注度最高的解决方案。MAP（Mapping Address and Port）技术是指无状态地对地址 和端口进行复用，根据报文格式又分为双重封装MAP-E和双重翻">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://wanglong_kevin.gitee.io/2018/12/31/MapT-rule/tuopu.png">
<meta property="og:image" content="https://wanglong_kevin.gitee.io/2018/12/31/MapT-rule/EA-bits.png">
<meta property="og:image" content="https://wanglong_kevin.gitee.io/2018/12/31/MapT-rule/v4v6.png">
<meta property="article:published_time" content="2018-12-31T01:37:07.000Z">
<meta property="article:modified_time" content="2018-12-31T01:37:07.000Z">
<meta property="article:author" content="Kevin">
<meta property="article:tag" content="ipv6">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://wanglong_kevin.gitee.io/2018/12/31/MapT-rule/tuopu.png">


<link rel="canonical" href="https://wanglong_kevin.gitee.io/2018/12/31/MapT-rule/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>Map-T rule | 冬天里的小木屋</title>
  






  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">冬天里的小木屋</h1>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">The Winter Room</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a>

  </li>
  </ul>
</nav>




</div>
        
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <section class="post-toc-wrap sidebar-panel">
          <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E8%83%8C%E6%99%AF%E4%BB%8B%E7%BB%8D"><span class="nav-number">1.</span> <span class="nav-text">背景介绍</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#MAP-T-%E5%9C%B0%E5%9D%80%E6%98%A0%E5%B0%84%E8%A7%84%E5%88%99"><span class="nav-number">2.</span> <span class="nav-text">MAP-T 地址映射规则</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#MAP-T-%E8%A7%84%E5%88%99%E8%A7%84%E5%88%92"><span class="nav-number">3.</span> <span class="nav-text">MAP-T 规则规划</span></a></li></ol></div>
      </section>
      <!--/noindex-->

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Kevin"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">Kevin</p>
  <div class="site-description" itemprop="description">NOT a coder, but an artist.</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">8</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">3</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">11</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



      </section>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">
      

      

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wanglong_kevin.gitee.io/2018/12/31/MapT-rule/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="Kevin">
      <meta itemprop="description" content="NOT a coder, but an artist.">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="冬天里的小木屋">
    </span>

    
    
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Map-T rule
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2018-12-31 09:37:07" itemprop="dateCreated datePublished" datetime="2018-12-31T09:37:07+08:00">2018-12-31</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-folder"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/%E7%BD%91%E7%BB%9C/" itemprop="url" rel="index"><span itemprop="name">网络</span></a>
                </span>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h2 id="背景介绍"><a href="#背景介绍" class="headerlink" title="背景介绍"></a>背景介绍</h2><p>为了保持IPv4业务持续性和促进IPv6产业的发展性，4over6场景凭借其兼顾IPv4业务和IPv6发展的特点，
成为长期演进方案研究的焦点。在4over6场景中，MAP技术结合了无状态和双重翻译/封装技术，
成为目前IETF关注度最高的解决方案。MAP（Mapping Address and Port）技术是指无状态地对地址
和端口进行复用，根据报文格式又分为双重封装MAP-E和双重翻译MAP-T两种。MAP技术是v4到v6的过渡技术。  </p>
<a id="more"></a>
<h2 id="MAP-T-地址映射规则"><a href="#MAP-T-地址映射规则" class="headerlink" title="MAP-T 地址映射规则"></a>MAP-T 地址映射规则</h2><p><img src="tuopu.png">
MAP-T技术拓扑如上，Host会获取一个v4地址和一个v6地址，当访问v4网络时，在CE上首先将Host的v4 LAN地址
做一个NAT转换，然后根据转换后的公网v4地址以及端口等信息根据一定规则映射成v6地址，报文到达BR上后，
BR根据规则来翻译出V4的信息，将v4报文发送出去，并将回来的报文再封装映射成v6报文，回送给CE。
由于32bits的IPV4地址是有限的，而16bits的port通常是盈余的，MAP 技术借用传输层端口来扩展IPV4地址，
即利用IP+Port-set 来区别不同用户，这样可以实现多个用户共享一个IPV4地址。   </p>
<pre><code>                    0                   1  
                    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5   
                    +-----------+-----------+-------+  
                    |    A      |   PSID    |  M    |     
                    |   &gt; 0     |           |       |  
                    +-----------+-----------+-------+  
                    | a bits    | k bits    |m bits |   </code></pre>
<p>为了确保IP+Port-set的唯一性，这里将端口的16bit划分为三部分，A、PSID、M。   </p>
<ul>
<li>关于A和a：因为0-1023是well-known端口，已经分配给一些特定应用使用，我们分配时避免使用此类端口。
在MAP中建议扩展到4095(2^12)，即 a(=PSID offset)默认值是4(16-12)。A的取值为非零，若a=0,则标识全部
port区间均可以分配。  </li>
<li>关于PSID和k: PSID的长度k决定了共享比率，共享比率=2^k，即传输层端口可以分成2^k份，每份共享给一个
CE使用，每个共享此IPV4地址的CE获得一个唯一的PSID，即获得一段唯一的port-set。   </li>
<li>关于M和m: M的长度m决定了port-set中端口的连续长度，连续长度=2^m。<br>通过这样的划分，可以获得2^k个port-set，每个port-set由唯一的PSID值标识，每PSID值对应的port-set
含有((2^a)-1)*(2^m)的端口号。接下来，通过实例来体验下port划分过程。<br>1、 给定共享比例R（=2^k=1024）和a(=PSID offset=4);<br>2、 推算出: a=4,k=10,m=2;<br>3、 列出PSID值和对应的port-set,   </li>
</ul>
<table>
<thead>
<tr>
<th>PSID</th>
<th align="center">Port-set-1(A=0001)</th>
<th align="center">Port-set-2(A=0010)</th>
<th>….</th>
<th align="center">Port-set-16(A=1111)</th>
</tr>
</thead>
<tbody><tr>
<td>0</td>
<td align="center">4096,4097,4098,4099</td>
<td align="center">8192,8193,8194,8195</td>
<td>….</td>
<td align="center">61440,61441,61442,61443</td>
</tr>
<tr>
<td>1</td>
<td align="center">4100,4101,4102,4103</td>
<td align="center">8196,8197,8198,8199</td>
<td>….</td>
<td align="center">61444,61445,61446,61447</td>
</tr>
<tr>
<td>2</td>
<td align="center">4104,4105,4106,4107</td>
<td align="center">8200,8201,8202,8203</td>
<td>….</td>
<td align="center">61448,61449,61450,61451</td>
</tr>
<tr>
<td>…..</td>
<td align="center">…..</td>
<td align="center">…….</td>
<td>…</td>
<td align="center">….</td>
</tr>
<tr>
<td>1023</td>
<td align="center">8188,8189,8190,8191</td>
<td align="center">12284,12285,12286,12287</td>
<td>…</td>
<td align="center">65532,65533,65534,65535</td>
</tr>
<tr>
<td>因此给定唯一的PSID值，即获得一组port-set。</td>
<td align="center"></td>
<td align="center"></td>
<td></td>
<td align="center"></td>
</tr>
<tr>
<td><img src="EA-bits.png"></td>
<td align="center"></td>
<td align="center"></td>
<td></td>
<td align="center"></td>
</tr>
<tr>
<td>接下来考虑如何将ipv4地址和port-set无状态映射成ipv6地址。MAP技术通过将IPv4地址的一部分和端口的</td>
<td align="center"></td>
<td align="center"></td>
<td></td>
<td align="center"></td>
</tr>
<tr>
<td>一部分特征嵌入到IPv6地址中实现，IPv4地址选的是IPv4-Addr-suffix，port-set 选择的是PSID，这样将IPv4</td>
<td align="center"></td>
<td align="center"></td>
<td></td>
<td align="center"></td>
</tr>
<tr>
<td>的地址信息和端口信息与IPv6地址建立了强关联。</td>
<td align="center"></td>
<td align="center"></td>
<td></td>
<td align="center"></td>
</tr>
<tr>
<td>对于IPv6用户而言，MAP-CE配置了End-user IPv6-prefix，可以通过Interface ID来生成用户的IPv6地址，</td>
<td align="center"></td>
<td align="center"></td>
<td></td>
<td align="center"></td>
</tr>
<tr>
<td>而对于IPv4用户而言，不会生成类似于IPv6地址的链路本地地址，那如何来生成标识IPv4属性的Interface ID，</td>
<td align="center"></td>
<td align="center"></td>
<td></td>
<td align="center"></td>
</tr>
<tr>
<td>进而合成代表IPv4地址的IPv6源地址呢？MAP技术采用IPv4 address和PSID的值组合形成Interface ID</td>
<td align="center"></td>
<td align="center"></td>
<td></td>
<td align="center"></td>
</tr>
<tr>
<td>来标识IPv4共享型用户，再与End-user IPv6-prefix一起合成IPv6地址，作为IPv4共享型用户在MAP Domain</td>
<td align="center"></td>
<td align="center"></td>
<td></td>
<td align="center"></td>
</tr>
<tr>
<td>中的唯一标识。</td>
<td align="center"></td>
<td align="center"></td>
<td></td>
<td align="center"></td>
</tr>
<tr>
<td><img src="v4v6.png"></td>
<td align="center"></td>
<td align="center"></td>
<td></td>
<td align="center"></td>
</tr>
</tbody></table>
<ul>
<li>对于IPv4address字段，若分配了一个共享IPv4地址，则IPv4address字段填写分配的IPv4地址，
长度是32比特，如果分配了IP-prefix，即分配一段地址给IPv4用户（有可能是个企业用户），
则IPv4address字段需要右填0补齐，比如给用户分配IPv4-prefix=”192.0.2.0/29”,则此处IPv4address
字段需要填写”0xC0000200”(十六进制）。</li>
<li>对于PSID字段，若EA-bits位提取的PSID值不足16bit时，左填0补充，如:PSID=“0xAC”，则此处的PSID
字段填“0x00AC”，如果分配了IPv4-prefix或者独享的IPv4-address时，则没有PSID值可以提取，
则此处的PSID字段填写“0x0000”。</li>
</ul>
<h2 id="MAP-T-规则规划"><a href="#MAP-T-规则规划" class="headerlink" title="MAP-T 规则规划"></a>MAP-T 规则规划</h2><p>在MAP技术中有三种MAP Rule，BMR(Basic Mapping Rule)、FMR(Forwarding Mapping Rule)
和DMR(Default Mapping Rule)，其中DMR在MAP-E中成为Destinations outside the MAP domain。</p>
<ul>
<li>BMR，必选项，用于计算MAP-CE的ipv4地址和port-set以及IPv6地址。BMR是需要配置在MAP域的每一个
路由器上，配置在MAP-CE上用于将IPv4用户数据进行NAT44和IPv6翻译/封装，配置在MAP-BR上用于
将IPv4地址从IPv6报文中解封装/解隧道，以及将回程流量的IPv4地址+port进行IPv6翻译和封装后，
在MAP域中按照IPv6路由转发到MAP-CE上。BMR的配置的基本参数包括：Rule-IPv6-prefix、
Rule-IPv4-prefix、EA-bits-length、PSID-offset，这些参数配置在MAP-CE上可以计算出共享的
IPv4地址和端口序列，以及MAP-CE的IPv6地址，举个实例分析下（参考上一节的映射图）。
MAP-CE获得属于IPv6前缀信息：（DHCPv6正常分配）<br>End-user IPv6-prefix: 2001:db8:0012:3400::/56<br>通过BMR下发的信息如下：<br>Rule-IPv6-prefix        : 2001:db8:0000::/40<br>Rule-IPv4-prefix        : 192.0.2.0/24 (0xC0000200/24)<br>EA-bits-length           : 16<br>PSID-offset(a)           : 4 (default)<br>则推导出如下信息（MAP-CE的共享A+P和IPv6地址）</li>
<li>EA-bit                      : 0x1234</li>
<li>IPv4-suffix                 : 0x12 (p=32-24=8)</li>
<li>PSID                        : 0x34 (q=o-p=16-8=8)</li>
<li>IPv4-address                : 192.0.2.18 (0xC0000212)</li>
<li>Port-set                    : 4928-4943, 9024-9039, ……, 62272-62287(a=4, A&gt;0; PSID=0x34)</li>
<li>IPv6-address                : 2001:db8:0012:3400:00C0:0002:1200:3400<br>第二条是FMR，是可选项，用于在mesh网络中实现MAP-CE间的互访流量直接通信，不需要通过MAP-BR中转。
这就是说在MAP-CE访问其他MAP-CE时，目的IPv6地址应该是对端MAP-CE的地址。报文的源IPv6地址是BMR
生成的，则目的MAP-CE的IPv6地址就成了FMR的转换目标。前面也提到每个MAP-CE的BMR是相同的
在一定范围），因此FMR和BMR也是可以相同的，即可以将BMR通过配置作为FMR。<br>第三条在MAP-T中定了“DMR”，代表报文的目的IPv4地址为MAP Domain域外的地址，通过BR进行转发到域外。
DMR含有两个参数Rule-IPv6-prefix和Rule-IPv4-prefix。Rule-IPv6-prefix的值是MAP BR的IPv6前缀，
Rule-IPv4-prefix值是0.0.0.0/0，即在MAP-CE上匹配IPv4路由时作为默认路由适用的映射规则。
在使用这条规则后，目的IPv6地址将通过DMR配置的Rule-IPv6-prefix+目的IPv4地址组成目的IPv6地址。</li>
</ul>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/ipv6/" rel="tag"># ipv6</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2018/12/15/IP-QOS-DSMARK/" rel="prev" title="IP QoS 之DSMARK">
                  <i class="fa fa-chevron-left"></i> IP QoS 之DSMARK
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2019/01/03/patch-syntax/" rel="next" title="quilt patch 语法记录">
                  quilt patch 语法记录 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
      </footer>
    
  </article>
  
  
  



      

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

    </div>
  </main>

  <footer class="footer">
    <div class="footer-inner">
      

      

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Kevin</span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

      








    </div>
  </footer>

  
  <script src="//cdn.jsdelivr.net/npm/animejs@3.2.0/lib/anime.min.js"></script>
<script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>

  















  

  

</body>
</html>
